﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ES.Admin
{
    using System.Linq.Expressions;

    public partial class FrmUrunler : Form
    {
        public FrmUrunler()
        {
            InitializeComponent();
        }
        private void Tazele(Expression<Func<Product, bool>> expression = null)
        {
            var categoriList = Program.Db.Products.AsQueryable();
            if (expression != null)
                categoriList = categoriList.Where(expression);
            dataGridView1.DataSource = categoriList.Select(d => new { Kimlik = d.Id, Başlık = d.Title, Fiyat = d.Price, Marka = d.Model, KdvOrani = d.Kdv }).ToList();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            var frm = new FrmYeniUrun();
            frm.ShowDialog();
            Tazele();
        }

        private void FrmUrunler_Load(object sender, EventArgs e)
        {
            Tazele();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var id = int.Parse(dataGridView1.CurrentRow.Cells[0].Value.ToString());
            var frm = new FrmYeniUrun { Id = id };
            frm.ShowDialog();
            Tazele();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            Tazele(d => d.Attributes.Contains(textBox1.Text) || d.Model.Contains(textBox1.Text) || d.Title.Contains(textBox1.Text) || d.Description.Contains(textBox1.Text));
        }

    }
}
